import { View } from "../../../mvc/core/View";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { FontUtil } from "../../../common/font/FontUtil";
import { Language } from "../../../../extend/language/Language";
import { GTextBar } from "../range/GTextBar";
import { GBoxDirection } from "../../../../com/mui/containers/globalVariable/GBoxDirection";
import { MuiEvent } from "../../../../com/mui/events/MuiEvent";
import { EColor } from "../../../../Message/Public/EColor";
import { IllustrateCollectConfig } from "../../resource/IllustrateCollectConfig";
import { MsgManager } from "../../manager/MsgManager";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { Cache } from "../../cache/Cache";
import { ColorConfig } from "../../resource/ColorConfig";
import { EquipmentUtil } from "../common/util/EquipmentUtil";
import { TIllustrateCollect } from "../../../../Message/Db/Tables/TIllustrateCollect";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
type int = number;
//class IllustrateRewardPanel
    
    export  class IllustrateRewardPanel extends View
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc5=null;
            ObjCreate.createBg(2, -1, 634, 30, this, ImagesConst.RbListHeader);
            ObjCreate.createBg(3, 32, 195, 49, this);
            ObjCreate.createBg(201, 32, 429, 49, this);
            var loc1=GlobalStyle.textFormat6;
            loc1.size = 18;
            loc1.font = FontUtil.EmbedTitleName;
            ObjCreate.createEmbedTextFiled(Language.getString(36309), 0, 5, 635, 30, this, GlobalStyle.getTextFormatCenter(loc1));
            var loc2=ObjCreate.createGTextField(Language.getString(36310), 20, 35, 100, 20, this, GlobalStyle.textFormat2);
            var loc3=ObjCreate.createGTextField(Language.getString(36311), 212, 35, 100, 20, this, GlobalStyle.textFormat2);
            var loc4=ObjCreate.createGTextField(Language.getString(36312), 430, 35, 100, 20, this, GlobalStyle.textFormat2);
            loc5 = [{"color": 41727, "text": Language.getString(36315)}, {"color": 16711935, "text": Language.getString(36316)}, {"color": 16742658, "text": Language.getString(36317)}];
            this._colorBmp = new Object /* flash.display.Bitmap */();
            this._colorBmp.x = 85;
            this._colorBmp.y = 55;
            addChild(this._colorBmp);
            this._colorBar = new GTextBar();
            this._colorBar.textWidth = 40;
            this._colorBar.verticalGap = 3;
            this._colorBar.x = 275;
            this._colorBar.y = 35;
            this._colorBar.direction = GBoxDirection.HORIZONTAL;
            this._colorBar.dataProvider = loc5;
            addChild(this._colorBar);
            this._colorBar.addEventListener(MuiEvent.GTABBAR_SELECTED_CHANGE, this.onColorBarSelectedChangeHandler);
            this._progressTxt = ObjCreate.createGTextField("20/50", 0, 35, 100, 20, this, GlobalStyle.textFormat6);
            this._progressTxt.x = loc4.x + loc4.textWidth;
            this._attriTxt = ObjCreate.createGTextField("", 0, 58, 500, 20, this, GlobalStyle.textFormat4);
            this._attriTxt.x = 240;
            return;
        }

        /* internal  */onColorBarSelectedChangeHandler(arg1: MuiEvent): void
        {
            if (!this._illustrateCollect) 
            {
                return;
            }
            var loc1=EColor._EColorBlue;
            var loc5=this._colorBar.selectedIndex;
            switch (loc5) 
            {
                case 0:
                {
                    loc1 = EColor._EColorBlue;
                    break;
                }
                case 1:
                {
                    loc1 = EColor._EColorPurple;
                    break;
                }
                case 2:
                {
                    loc1 = EColor._EColorOrange;
                    break;
                }
            }
            var loc2=this._illustrateCollect.id;
            var loc3=IllustrateCollectConfig.instance.getIllustrateByIdColor(loc2, loc1);
            var loc4="";
            if (loc3) 
            {
                loc4 = loc3.attribute;
            }
            else if (this._illustrateCollect) 
            {
                loc1 = this._illustrateCollect.color;
                loc4 = this._illustrateCollect.attribute;
                MsgManager.showRollTipsMsg(Language.getString(380002));
            }
            this.updateReward(loc4, loc1);
            return;
        }

        /* internal  */createTextBar(arg1: int, arg2: int, arg3: Array<any>): GTextBar
        {
            var loc1;
            (loc1 = new GTextBar()).textWidth = 40;
            loc1.verticalGap = 3;
            loc1.x = arg1;
            loc1.y = arg2;
            loc1.direction = GBoxDirection.HORIZONTAL;
            loc1.dataProvider = arg3;
            loc1.selectedIndex = 0;
            addChild(loc1);
            return loc1;
        }

        /* internal  */onResLoaded(): void
        {
            if (this._illustrateCollect) 
            {
                this._colorBmp.bitmapData = GlobalClass.getBitmapData("color" + this._colorInt);
            }
            else 
            {
                this._colorBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.color3);
            }
            return;
        }

        public updateReward(arg1: string, arg2: int, arg3: Boolean=false): void
        {
            var loc4=null;
            var loc5=null;
            var loc6=0;
            var loc8=null;
            this._attriTxt.text = "";
            var loc1=Cache.instance.role.entityInfo.career;
            var loc2=arg1.split("#");
            var loc3=new Map<any, any> /* flash.utils.Dictionary */();
            loc6 = 0;
            while (loc6 < loc2.length) 
            {
                if ((loc4 = loc2[loc6]) != "") 
                {
                    loc5 = loc4.split(",");
                    loc3[loc5[0]] = loc5[1];
                }
                ++loc6;
            }
            var loc7=ColorConfig.instance.getItemColor(arg2).color;
            var loc9=EquipmentUtil.getSelfCareerAttribute(loc1, loc3);
            loc6 = 0;
            while (loc6 < loc9.length) 
            {
                loc8 = loc9[loc6];
                this._attriTxt.htmlText = "<font color=\'" + loc7 + "\'>" + this._attriTxt.text + loc8.name + "+" + loc8.value + "&nbsp;&nbsp;&nbsp;&nbsp;</font>";
                ++loc6;
            }
            if (arg3) 
            {
                this._colorBar.selectedIndex = arg2 - 3;
            }
            return;
        }

        public updateProgress(arg1: TIllustrateCollect): void
        {
            var loc1=null;
            var loc3=null;
            var loc6=0;
            var loc7=null;
            var loc8=0;
            this._illustrateCollect = arg1;
            if (!arg1) 
            {
                return;
            }
            loc1 = Cache.instance.illustrate.getIllustrateActiveInfoById(arg1.id);
            var loc2=new Map<any, any> /* flash.utils.Dictionary */();
            if (loc1) 
            {
                loc2 = loc1.pieces;
            }
            var loc4=[];
            if (arg1) 
            {
                if (loc3 = arg1.compose.split("#")) 
                {
                    loc8 = 0;
                    while (loc8 < loc3.length) 
                    {
                        if (!(loc3[loc8] == null) && !(loc3[loc8] == "")) 
                        {
                            loc4.push(loc3[loc8]);
                        }
                        ++loc8;
                    }
                }
            }
            var loc5=0;
            var loc9=0;
            var loc10=loc2;
            for(loc6 of loc10) 
            {
                loc5 = loc5 + 1;
            }
            this._progressTxt.htmlText = "<font color=\'#00ff00\'>" + loc5 + "</font>/" + loc4.length;
            loc7 = IllustrateCollectConfig.instance.getIllustrateByIdColor(arg1.id, arg1.color + 1);
            this._colorInt = EColor._EColorBlue;
            if (loc7 && loc1 && loc1.status >= EColor._EColorBlue) 
            {
                if (loc1.status >= EColor._EColorOrange) 
                {
                    this._colorInt = loc1.status;
                }
                else 
                {
                    this._colorInt = loc1.status + 1;
                }
            }
            else 
            {
                this._colorInt = arg1.color;
            }
            LoaderHelp.addResCallBack(ResFileConst.Illustrate, this.onResLoaded);
            return;
        }

        /* internal */ /* var */_colorBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_progressTxt: GTextFiled;

        /* internal */ /* var */_attriTxt: GTextFiled;

        /* internal */ /* var */_colorBar: GTextBar;

        /* internal */ /* var */_illustrateCollect: TIllustrateCollect;

        /* internal */ /* var */_colorInt: int=3;
    }
